package com.ly.houses.api;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ly.houses.common.Login;
import com.ly.houses.mapper.LoginMapper;
import com.ly.houses.model.Plate;
import com.ly.houses.model.User;
import com.ly.houses.service.PlateService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/plateApi")
public class PlateApi {
    @Resource
    private PlateService plateService;
    @Resource
    private LoginMapper loginMapper;
    @GetMapping("/list")
    public PageInfo listPlate(@Login User user,Long areaId, String name, int page, int pageSize){
        if(user==null){
            PageInfo pageInfo = new PageInfo(new ArrayList());
            return pageInfo;
        }
        User isUser=loginMapper.getByOpenId(user.getOpenId());
        if(isUser==null){
            PageInfo pageInfo = new PageInfo(new ArrayList());
            return pageInfo;
        }
        PageHelper.startPage(page,pageSize);
        List<Plate> list=plateService.listPlateByName(name,areaId);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }
}
